#! /usr/bin/env python3


import rospy
import tf2_ros
import tf
from geometry_msgs.msg import TransformStamped
from tf2_ros import StaticTransformBroadcaster

if __name__=="__main__":
    rospy.init_node("static_transform_publisher2")
     #创建广播的发布者
    broadcaster = StaticTransformBroadcaster()
    #创建一个父子坐标系
    tfs2=TransformStamped()
    tfs2.header.frame_id="world"
    tfs2.header.stamp=rospy.Time.now()
    tfs2.header.seq=101
    tfs2.child_frame_id="son2"
    tfs2.transform.translation.x=5.0
    tfs2.transform.translation.y=5.0
    tfs2.transform.translation.z=0.0
    #将欧拉角转换为四元数
    qtn2=tf.transformations.quaternion_from_euler(0,0,0)
    tfs2.transform.rotation.x=qtn2[0]
    tfs2.transform.rotation.y=qtn2[1]
    tfs2.transform.rotation.z=qtn2[2]
    tfs2.transform.rotation.w=qtn2[3]
    #发布广播
    broadcaster.sendTransform(tfs2)
    print("success sendTransform tfs2")
    rospy.spin()

